﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.Controls
{
	public partial class ModuleArticleSelector : RepeaterSelector<ModuleArticleId, List<ModuleArticles.ModuleArticleForSelector>>
	{
		#region 属性
		protected override Wuqi.Webdiyer.AspNetPager Pager
		{
			get { return pager; }
		}

		protected override Repeater DataList
		{
			get { return List; }
		}

		public int? SiteId
		{
			get { return (int?)ViewState["SiteId"]; }
			set { ViewState["SiteId"] = value; }
		}

		public string ModuleName
		{
			get { return Convert.ToString(ViewState["ModuleName"]); }
			set { ViewState["ModuleName"] = value; }
		}
		#endregion

		#region 函数
		protected override PaginationInfo<List<ModuleArticles.ModuleArticleForSelector>> GetData()
		{
			return ModuleArticles.GetPaginationSelectorList(SiteId
				, IntExtensions.ParseOrNull(TbID.Text)
				, ModuleName
				, TbKeyword.Text
				, pager.PageSize, pager.CurrentPageIndex);
		}

		/// <summary>
		/// 取得 ListItem 的标识符。
		/// </summary>
		/// <param name="item">列表的 ListItem。</param>
		/// <returns>ListItem 的标识符。</returns>
		protected override ModuleArticleId GetListItemType(RepeaterItem item)
		{
			ModuleArticleId identifier = new ModuleArticleId();
			HiddenField control;

			control = (HiddenField)item.FindControl("Identifier_ModuleID");
			identifier.ModuleId = Convert.ToInt32(control.Value);
			control = (HiddenField)item.FindControl("Identifier_ArticleID");
			identifier.ArticleId = Convert.ToInt32(control.Value);

			return identifier;
		}
		#endregion
	}
}